package cn.seaboot.admin.quartz.service;

import cn.seaboot.admin.quartz.bean.ScheduleLog;
import cn.seaboot.admin.quartz.dao.ScheduleLogDao;
import cn.seaboot.commons.core.Snowflake;
import cn.seaboot.commons.core.SnowflakeFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
* Service
* 定时任务执行日志 [t_schedule_log]
* @author Mr.css on 2018-6-20
*/
@Service
public class ScheduleLogService {
    private final Snowflake snowflake = SnowflakeFactory.createSnowflake();

    @Resource
    private ScheduleLogDao ScheduleLogDao;

    /**
     * 增
     *
     * @param pojo pojo
     * @return affected rows
     */
    public int insert(ScheduleLog pojo){
        pojo.setId(snowflake.nextId());
        return ScheduleLogDao.insert(pojo);
    }

    /**
     * 删
     *
     * @param id id
     * @return affected rows
     */
    public int deleteById(String id){
        return ScheduleLogDao.deleteById(id);
    }

    /**
     * 改
     *
     * @param pojo pojo
     * @return affected rows
     */
    public int updateById(ScheduleLog pojo) {
        return ScheduleLogDao.updateSampleById(pojo);
    }

    /**
     * 查
     *
     * @param id id
     * @return pojo
     */
    public ScheduleLog queryById(String id){
        return ScheduleLogDao.selectById(id);
    }

    /**
     * 查
     *
     * @param id job-id
     * @return pojo
     */
    public ScheduleLog queryRunningJobById(String id){
        return ScheduleLogDao.selectById(id);
    }

    /**
     * 查列表
     *
     * @param params 参数
     * @return list
     */
    public List<ScheduleLog> queryList(Map<String, Object> params) {
        return ScheduleLogDao.selectList(params);
    }
}
